define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'dts/approve/contract/index' + location.search,
                    add_url: 'dts/approve/contract/add',
                    edit_url: 'dts/approve/contract/edit',
                    del_url: 'dts/approve/contract/del',
                    multi_url: 'dts/approve/contract/multi',
                    import_url: 'dts/approve/contract/import',
                    table: 'dts_approve_contract',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                search: false,
                columns: [
                    [
                        {checkbox: true},
                        // {field: 'id', title: __('Id')},
                        // {field: 'todo_id', title: __('Todo_id')},
                        {field: 'admin.nickname', title: __('Admin_id'), operate: 'LIKE'},
                        {field: 'deptname', title: __('Deptname'), operate: 'LIKE'},
                        {field: 'name', title: __('Name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'isprice', title: __('Isprice'), searchList: {"0":__('Isprice 0'),"1":__('Isprice 1')}, formatter: Table.api.formatter.normal},
                        {field: 'enquirymsg', title: __('Enquirymsg'), operate: false},
                        {field: 'filingsno', title: __('Filingsno'), operate: 'LIKE'},
                        {field: 'undertake_dept.name', title: __('Undertake_dept_id'), operate: 'LIKE'},
                        {field: 'undertake_admin.nickname', title: __('Undertake_admin_id'), operate: 'LIKE'},
                        {field: 'undertake_time', title: __('Undertake_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'performing_party', title: __('Performing_party'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'content', title: __('Content'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'pay_agree', title: __('Pay_agree'), operate: false, table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'pay_price', title: __('Pay_price'), operate: false},
                        {field: 'pay_method', title: __('Pay_method'), operate: 'LIKE'},
                        {field: 'deadline', title: __('Deadline'), operate:'RANGE', addclass:'datetimerange', autocomplete:false},
                        {field: 'copies_num', title: __('Copies_num'), operate: false},
                        {field: 'remark', title: __('Remark'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'examine_dept.nickname', title: __('Examine_dept_id'), operate: 'LIKE'},
                        {field: 'examine_leader.nickname', title: __('Examine_leader_id'), operate: 'LIKE'},
                        {field: 'examine_finance.nickname', title: __('Examine_finance_id'), operate: 'LIKE'},
                        {field: 'examine_advisor.nickname', title: __('Examine_advisor_id'), operate: 'LIKE'},
                        {field: 'examine_legal.nickname', title: __('Examine_legal_id'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4'),"5":__('Status 5'), '600':__('Status 600'), '601':__('Status 601'), '602':__('Status 602'), '603':__('Status 603'), '604':__('Status 604'),"7":__('Status 7')}, formatter: Table.api.formatter.normal},
                        {field: 'refuse', title: __('Refuse'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'copy.nickname', title: __('Copy_ids'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'operate', title: __('Operate'), 
                            table: table, 
                            events: Table.api.events.operate, 
                            /*隐藏自带编辑按钮、条件隐藏 */
							formatter: function(value,row,index){
							    var that = $.extend({},this);
                                var table = $(that.table).clone(true);
                                $(table).data("operate-edit",null);
                                $(table).data("operate-del",null);
                                that.table = table;
							    return Table.api.formatter.operate.call(that,value,row,index)
							},
                            buttons: [
                                {
                                    name: 'export',
                                    title: __('导出'),
                                    classname: 'btn btn-xs btn-success btn-click',
                                    icon: 'fa fa-download',
                                    click: function(data, row) {
                                        window.open(Fast.api.fixurl('dts/approve/contract/export?ids=' + row.id), '导出');
                                        return false;
                                    },
                                    visible: function (row) { return [5,6].indexOf(row.status) >= 0; }
                                }
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
